package edu.pku.sei.modeler.uml.commands.timing;

import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.structure.MetaLink;
import edu.pku.sei.modeler.model.structure.MetaNode;
import edu.pku.sei.modeler.model.uml.temp.timeline.TimeLine;
import edu.pku.sei.modeler.model.uml.temp.timeline.TimingLifeLine;
import edu.pku.sei.modeler.uml.commands.ConnectionModelCreateCommand;
import edu.pku.sei.modeler.uml.commands.UMLConnectionCreateCommand;

public class TimeLineCreateCommand extends UMLConnectionCreateCommand {

	public TimeLineCreateCommand(MetaLink link, MetaNode src) {
		super(link, src);
		this.setModelCmd(new TimeLineModelCreateCommand(link.getModelElement(), src.getModelElement()));
	}
	
	@Override
	public void execute() {
		addLink();
	}
	
	public class TimeLineModelCreateCommand extends ConnectionModelCreateCommand {

		public TimeLineModelCreateCommand(MetaModelElement connectionModel,
				MetaModelElement sourceModel) {
			super(connectionModel, sourceModel);
		}
		
		@Override
		public void execute() {
			if (sourceModel instanceof TimingLifeLine) {
				((TimingLifeLine)sourceModel).setTimeLine((TimeLine) connectionModel);
			}
		}
		
		@Override
		public void undo() {
			if (sourceModel instanceof TimingLifeLine) {
				((TimingLifeLine)sourceModel).setTimeLine(null);
			}
		}
		
	}

}
